package com.example.firstapplication;

import java.util.Random;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.text.InputType;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.ToggleButton;

public class TextPlay extends Activity implements View.OnClickListener {

	Button button;
	ToggleButton toggleButton;
	TextView textView;
	EditText editText;
	float size;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.text);
		
		setValues();
		
	
		toggleButton.setOnClickListener(this);
		
		button.setOnClickListener(this);
	}

	private void setValues() {
		button=(Button) findViewById(R.id.button1);
		toggleButton=(ToggleButton) findViewById(R.id.toggleButton1);
		textView=(TextView) findViewById(R.id.textView1);
		editText=(EditText) findViewById(R.id.eText);
		size=textView.getTextSize();
	}

	@Override
	public void onClick(View v) {
		switch(v.getId()){
		case R.id.button1:
			String check=editText.getText().toString();
			
			textView.setText(check);
			if(check.contentEquals("left")){
				textView.setGravity(Gravity.LEFT);
			}else if(check.contentEquals("center")){
				textView.setGravity(Gravity.CENTER);
			}else if(check.contentEquals("right")){
				textView.setGravity(Gravity.RIGHT);
			}else if(check.contentEquals("blue")){
				textView.setTextColor(Color.BLUE);
			}else if(check.contentEquals("WTF")){
				textView.setText("WTF!!!!!");
				Random random=new Random();
				textView.setTextSize(random.nextInt(75));
				textView.setTextColor(Color.rgb(random.nextInt(256), random.nextInt(256), random.nextInt(256)));
				switch(random.nextInt(3)){
				case 0:
					textView.setGravity(Gravity.LEFT);
					break;
				case 1:textView.setGravity(Gravity.CENTER);
				    break;
				case 2:textView.setGravity(Gravity.RIGHT);
					break;
				default:
					textView.setGravity(Gravity.CENTER);
				}
			}else{
				textView.setText("invalid");
				textView.setGravity(Gravity.CENTER);
				textView.setTextSize(size);
				textView.setTextColor(Color.BLACK);
			}
			break;
		case R.id.toggleButton1:
			if(toggleButton.isChecked()){
				editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
				
			}else{
				editText.setInputType(InputType.TYPE_CLASS_TEXT);
			}
			break;
		}
		
	}
}
